package com.hbpu.encap.set;

import java.util.HashSet;
import java.util.Objects;

@SuppressWarnings({"all"})
public class HashSetExercise02 {
    public static void main(String[] args) {
        Employee01 mike = new Employee01("mike", 22, 2024, 12, 9);
        Employee01 jack = new Employee01("jack", 25, 2024, 9, 8);
        Employee01 john = new Employee01("john", 31, 2024, 5, 6);
        Employee01 john01 = new Employee01("john", 31, 2024, 5, 6);

        HashSet hashSet = new HashSet();
        hashSet.add(mike);
        hashSet.add(john);
        hashSet.add(jack);
        hashSet.add(john01);

        for (Object o : hashSet) {
            System.out.println(o);
        }
    }
}

class Employee01 {
    private String name;
    private double sal;
    private MyDate date;

    public Employee01(String name, double sal, int year, int month, int day) {
        this.name = name;
        this.sal = sal;
        this.date = new MyDate(year, month, day);
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getSal() {
        return sal;
    }

    public void setSal(double sal) {
        this.sal = sal;
    }

    public MyDate getDate() {
        return date;
    }

    public void setDate(MyDate date) {
        this.date = date;
    }

    @Override
    public String toString() {
        return "Employee01{" +
                "name='" + name + '\'' +
                ", sal=" + sal +
                ", date=" + date +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (o == null || getClass() != o.getClass()) return false;
        Employee01 that = (Employee01) o;
        return Double.compare(sal, that.sal) == 0 && Objects.equals(name, that.name) && Objects.equals(date, that.date);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, sal, date);
    }
}


class MyDate {
    private int year;
    private int month;
    private int day;

    public MyDate(int year, int month, int day) {
        this.year = year;
        this.month = month;
        this.day = day;
    }

    public int getYear() {
        return year;
    }

    public void setYear(int year) {
        this.year = year;
    }

    public int getMonth() {
        return month;
    }

    public void setMonth(int month) {
        this.month = month;
    }

    public int getDay() {
        return day;
    }

    public void setDay(int day) {
        this.day = day;
    }

    @Override
    public boolean equals(Object o) {
        if (o == null || getClass() != o.getClass()) return false;
        MyDate myDate = (MyDate) o;
        return year == myDate.year && month == myDate.month && day == myDate.day;
    }

    @Override
    public int hashCode() {
        return Objects.hash(year, month, day);
    }
}